package edu.biwu.cookie01;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * 1.如何创建Cookie
 *      利用jakarta.sevlet.http.Cookie 类构造Cookie，数据格式类似一种map结构（key=value）
 *      public Cookie(String name ,String value):创建name = value的Cookie
 * 2.如何将Cookie发送给浏览器让其存储
 *      由于是响应非客户端，所以考虑使用response中的方法
 *      public void addCookie(Cookie cookie):将cookie响应给客户端
 */
@WebServlet("/cookie/send")
public class SendCookie extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie cookie = new Cookie("id", "123");
        response.addCookie(cookie);
        response.addCookie(new Cookie("zhangsan" , "12344"));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
